package DesignPattern.Builder.ProtoType.DeepClone;

import java.io.*;

public class CitationTest {
    public static void main(String[] args) throws Exception {
        Citation citation = new Citation();
        Student student = new Student();
        student.setName("张三");
        citation.setStudent(student);

        // 使用写入文件后序列化以及反序列化方式实现深克隆
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("src/main/java/DesignPattern/Builder/ProtoType/FileSave/student.txt"));
        oos.writeObject(citation);
        oos.close();

        // 读取对象
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("src/main/java/DesignPattern/Builder/ProtoType/FileSave/student.txt"));
        Citation citation1 = (Citation) ois.readObject();
        ois.close();

        Student student1 = citation1.getStudent();
        student1.setName("李四");

        citation.show();
        citation1.show();
    }
}
